﻿@{
    Layout = null;
}
<link href="../../Content/jquery-easyui-1.3.1/themes/icon.css" rel="stylesheet" />
<link href="../../Content/jquery-easyui-1.3.1/themes/default/easyui.css" rel="stylesheet" />
<link href="../../Content/Site.css" rel="stylesheet" />
<script src="../../Content/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
<script src="../../Content/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
<script src="../../Content/jquery-easyui-1.3.1/locale/easyui-lang-zh_CN.js"></script>
@*修改时间格式的Js文件*@
<script src="../../Content/jquery-easyui-1.3.1/datapattern2.js"></script>

<script type="text/javascript">

    var url;
    function add() {
        $('#dlg').dialog('open').dialog('setTitle', '新建');
        $('#fm').form('clear');
        $('#SubTime').attr("readonly", false);
        ////隐藏
        //$('#USubTime').attr("display", "none");
        //$('#ULastModifiedOn').attr("display", "none");
        url = 'Regist';
    }
    function edit() {

        var rows = $('#dg').datagrid('getSelections');

        if (rows.length == 1) {
            $('#dlg').dialog('open').dialog('setTitle', '编辑');
            ////显示
            //$('#USubTime').attr("display", "block");
            //$('#ULastModifiedOn').attr("display", "block");
            //设置只读
            $('#SubTime').attr("readonly", "readonly");
            $('#fm').form('load', rows[0]);
            //时间格式 装换
            var subtime = rows[0]['SubTime'];
            subtime = eval(subtime.replace(/\/Date\((\d+)\)\//gi, 'new Date($1)')).pattern('yyyy-MM-dd hh:mm:ss');
            $('#SubTime').val(subtime);

            url = 'UpdateInfo';
        }
        else if (rows.length > 1) {
            $.messager.alert("提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + rows.length + "</font>行");
        }
        else {
            $.messager.alert("提示", "请先选择记录.");
        }
    }
    function save() {
        $('#fm').form('submit', {

            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                if (result == "OK") {
                    $('#dlg').dialog('close');
                    $("#dg").datagrid("reload");
                    $.messager.alert("提示", "操作成功!");
                }
                else {
                    $.messager.alert("提示", result);
                }
            }
        });
    }
    function destroy() {
        //获取到用户选定的某一列的ID号
        var deleteinfo = $("#dg").datagrid("getSelections");
        //判断用户选择了多少条数据
        // //异步将删除的ID发送到后台，后台删除之后，返回前台OK，前台刷新表格
        if (deleteinfo.length >= 1) {
            var ids = "";   //1,2,3,4
            for (var i = 0; i < deleteinfo.length; i++) {
                ids += deleteinfo[i].ID + ",";
            }
            //去掉最后的一个,
            ids = ids.substring(0, ids.length - 1);

            //遍历出删除用户的信息
            var NameList = "";
            for (var i = 0; i < deleteinfo.length; i++) {
                NameList += deleteinfo[i].ActionName + ",";
            }
            NameList = NameList.substring(0, NameList.length - 1);

            //发送异步请求删除数据
            $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + NameList + "</font>采集器信息吗？", function (DeleteInfo) {
                if (DeleteInfo) {
                    $.post("DeleteInfo", { deleteInfoID: ids }, function (data) {
                        if (data == "OK") {
                            $.messager.alert("友情提示", "删除成功");
                            $("#dg").datagrid("reload");

                            //当删除完成的时候清除掉所选择的长度，防止下次选择的时候还记录了上次的内容
                            $("#dg").datagrid("clearSelections");
                        }
                        else {
                            $.messager.alert("友情提示", data);
                        }
                    });
                }
            });
        }
        else {
            $.messager.alert("友情提示", "请您选择要删除的数据");
        }
    }
</script>


<div id="jnContext">
    <table id="dg" title="权限管理" class="easyui-datagrid"
           url="GetAll"
           toolbar="#toolbar" pagination="true" sortname="ActionName"
           rownumbers="true" fitcolumns="true" singleselect="false">
        <thead>
            <tr>
                <th field="ID">权限编号</th>
                <th field="ActionName">权限名</th>
                <th field="ActionType"
                    data-options="formatter:function (value, row, index){if(value==1)return '菜单';else if(value==0)return '控件'; else return '未知';}">
                    类型
                </th>
                <th field="RequestUrl">请求路径</th>
                <th field="RequestHttpType">请求类型</th>
                <th field="ParentID">父节点ID</th>
                <th field="SubTime"
                    data-options="formatter:function (value, row, index) {  return (eval(value.replace(/\/Date\((\d+)\)\//gi, 'new Date($1)'))).pattern('yyyy-MM-dd hh:mm:ss');}">
                    用户创建时间
                </th>

               
                <th field="Describe">权限描述</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="add()">新建</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="edit()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="destroy()">删除</a>
    </div>
</div>


<div id="dlg" class="easyui-dialog" style="width: 500px; height: 450px; padding: 10px 20px"
     closed="true" resizable="true" modal="true" align="center">

    <form id="fm" method="post">

        <table>
            <tr>
                <th colspan="2">权限管理</th>
            </tr>

            <tr style="display:none">
                <td><label for="ID">权限编号：</label></td>
                <td><input class="easyui-validatebox" id="ID" name="ID" /></td>

            </tr>

            <tr>
                <td><label for="ParentID">父节点编号：</label></td>
                <td><input class="easyui-validatebox" id="ParentID" name="ParentID" /></td>

            </tr>

            <tr>
                <td><label for="ActionName">权限名：</label></td>
                <td><input class="easyui-validatebox" id="ActionName" name="ActionName" required="true" /></td>
            </tr>

            <tr>
                <td><label for="RequestUrl">请求路径：</label></td>
                <td><input class="easyui-validatebox" id="RequestUrl" name="RequestUrl" required="true" /></td>
            </tr>

            <tr>
                <td><label for="RequestHttpType">请求类型：</label></td>
                <td>
                    <select id="RequestHttpType" class="easyui-combobox" name="RequestHttpType" required="true">
                        <option value="HttpGet">HttpGet</option>
                        <option value="HttpPost">HttpPost</option>
                    </select>
                </td>
                
            </tr>

            <tr id="USubTime">
                <td><label for="SubTime">创建日期：</label></td>
                <td><input class="easyui-validatebox" id="SubTime" name="SubTime" /></td>
            </tr>

            <tr>
                <td><label for="ActionType">类型：</label></td>
                <td>
                    <select id="ActionType" class="easyui-combobox" name="ActionType">
                        <option value=0>控件</option>
                        <option value=1>菜单</option>
                    </select>
                </td>
           </tr>

            <tr>

                <td><label for="Describe">权限描述：</label></td>
                <td><textarea id="Describe" name="Describe" class="easyui-validatebox" style="height:150px;"></textarea></td>
            </tr>

            <tr>
                <td colspan="2" style="text-align:center; padding-top:10px">
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="save()">确定</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel"
                       onclick="javascript:$('#dlg').dialog('close'); ">关闭</a>
                </td>
            </tr>

        </table>
    </form>

</div>



